import Guide from '~/components/layout/guide'
import { InlineCode } from '~/components/text/code'
import Caption from '~/components/text/caption'
import Link from '~/components/text/link'
import Note from '~/components/text/note'

export const meta = {
  title: 'Prevent Uploading Source Paths with `.nowignore` on ZEIT Now',
  description:
    'Use a .nowignore file to prevent the uploading of source paths when deploying with ZEIT Now.',
  published: '2019-01-24T03:00:00.860Z',
  authors: ['unicodeveloper', 'msweeneydev'],
  url: '/guides/prevent-uploading-sourcepaths-with-nowignore',
  editUrl: 'pages/guides/prevent-uploading-sourcepaths-with-nowignore.mdx',
  lastEdited: '2020-01-24T23:33:43.000Z'
}

[ZEIT Now](/) supports configuration required to ignore source files and paths within your project. With a `.nowignore` file in your project directory, a source path can be prevented from being uploaded to ZEIT Now.

## File Syntax

The syntax of a `.nowignore` file matches that of the popular [`.gitignore` file](https://git-scm.com/docs/gitignore#_pattern_format) used in ignoring files when uploading to a Git repository.

An example of a `.nowignore` file that prevents an `/image` directory and `/private.html` file within a project from being uploaded to ZEIT Now would look like this:

```
image
private.html
```

<Caption>
  An example <InlineCode>.nowignore</InlineCode> file.
</Caption>

## Allowlist

A typical `.nowignore` file assumes all files are allowed and each entry is a pattern to ignore. Alternatively, you may chose to ignore all files and each entry is a pattern to allow.
The first step is to add a wildcard `/*` as the first line in `.nowignore`. This will ensure all directories and files in the project root are ignored. The following lines must start with a `!` to invert the ignore action and ensure the directory or file is allowed.

```
# Ignore everything (folders and files) on root only
/*
!api
!now.json
!*.html
```

<Caption>
  An example <InlineCode>.nowignore</InlineCode> file using the "allowlist" pattern.
</Caption>

## Uploaded Files

Aside from the [default exclusions](/docs/v2/build-step/#ignored-files-and-folders), all files within your project are uploaded to ZEIT Now if no source path is specified to be excluded in a [`.nowignore` configuration file](https://zeit.co/docs/v2/deployments/ignoring-source-paths).

<Note>
  You can find the complete list of files and directories excluded by default in
  the{' '}
  <Link href="/docs/v2/build-step/#ignored-files-and-folders">
    ZEIT Now documentation
  </Link>
  .
</Note>

Worthy of note is that not all uploaded files are served on ZEIT Now. So, what files are served?

## Served Files

If [ZEIT Now](/) is required to build your project, the non-targeted files are prevented from being deployed and served on ZEIT Now.

The use of a `.nowignore` configuration file allows you to keep private files safe and also makes your deployment faster by uploading only the essential files.

export default ({ children }) => <Guide meta={meta}>{children}</Guide>

export const config = {
  amp: 'hybrid'
}
